<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');
function removeSystemCaching_ioc(){
	$ci = &get_instance();
	//$ci->pyrocache->delete('countriesInTheWorld');
	//$ci->pyrocache->delete('hourNminuteCache');
	
	$dir = './system/cms/cache/default/';
	foreach(glob($dir.'*.cache') as $v){
	   @unlink($v);
	}
	getCountryData_ioc();
	getHourAndMinuteOptionData_ioc();
}

function getEscortCategoryData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_CATEGORY)->result() as $item){
		$return_array[$item->code]	= $item->category;
	}
	
	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;
}

function getSexualOrientationData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_SEXUAL_ORIENTATION)->result() as $item){
		$return_array[$item->code]	= $item->orientation;
	}
	
	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;
}

function getCountryData_ioc($country_id = 0){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$country_array = array();
	
	if(isset($country_id) AND $country_id != 0){
		$result = $ci->db->where('id',$country_id)->order_by('country_name','ASC')->get(TBL_COUNTRY)->result();
		$country_array[$result[0]->id] = ucwords( strtolower( $result[0]->country_name ) );
		return $country_array;
	}
	if ( ! $country_array = $ci->pyrocache->get('countriesInTheWorld')){
		
		foreach( $ci->db->order_by('country_name','ASC')->get(TBL_COUNTRY)->result() as $item){
			$country_array[$item->id] = ucwords( strtolower( html_entity_decode($item->country_name) ) );
		}
		$ci->pyrocache->write($country_array, 'countriesInTheWorld');
	}
	$ci->db->set_dbprefix($current_dbprefix);
	return $country_array;
	//$ci->pyrocache->delete('countriesInTheWorld');	
}

function getStateData_ioc($country_id = 0,$state_id = 0){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$state_array = array();
	
	if(!$country_id){
		return array();
	}
	if($state_id == -2){
		return array();
	}
	
	$COUNTRY = $ci->countries_entity->init('id',$country_id);
	if(!$COUNTRY){
		return array();
	}
	if(isset($state_id) AND $state_id != 0){
		if($COUNTRY->getCountryCode() == 'ES'){
			$rs = $ci->db->where('id',$state_id)->order_by('region_name_spanish','ASC')->get(TBL_SPAIN_STATE)->result();
			if($rs){
				$state_array[$rs[0]->id] =  ucwords( strtolower( html_entity_decode($rs[0]->region_name_spanish) ) );
				return $state_array;
			}
		}else{
			$rs = $ci->db->where( array('id'=>$state_id))->order_by('state_name','ASC')->get(TBL_STATE)->result();
			if($rs){
				$state_array[$rs[0]->id] =  ucwords( strtolower( html_entity_decode($rs[0]->state_name) ) );
				return $state_array;
			}
		}
	}
	//if ( ! $state_array = $ci->pyrocache->get('state_country_id_'.$country_id)){
		if($COUNTRY->getCountryCode() == 'ES'){
			foreach($ci->db->order_by('region_name_spanish','ASC')->get(TBL_SPAIN_STATE)->result() as $item){
				$state_array[$item->id] =  ucwords( strtolower( html_entity_decode($item->region_name_spanish) ) );
			}
		}else{
			foreach($ci->db->where('country_code',$COUNTRY->getCountryCode())->order_by('state_name','ASC')->get(TBL_STATE)->result() as $item){
				$state_array[$item->id] =  ucwords( strtolower( html_entity_decode($item->state_name) ) );
			}
		}
	//	$ci->pyrocache->write($state_array, 'state_country_id_'.$country_id);
	//}
	$ci->db->set_dbprefix($current_dbprefix);
	return $state_array;
}

function getProvinceData_ioc($country_id = 0, $state_id = 0, $province_id= 0){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$province_array = array();
	
	if(!$country_id){
		return array();
	}
	if($province_id == -2){
		return array();
	}
	$COUNTRY = $ci->countries_entity->init('id',$country_id);
	if(!$COUNTRY){
		return array();
	}
	
	if(isset($province_id) AND $province_id != 0){
		if($COUNTRY->getCountryCode() == 'ES'){
			$rs = $ci->db->where('id',$province_id)->order_by('province_name_spanish','ASC')->get(TBL_SPAIN_PROVINCE)->result();
			if($rs){
				$province_array[$rs[0]->id] =  ucwords( strtolower( html_entity_decode($rs[0]->province_name_spanish) ) );
				return $province_array;
			}
		} 
	}
	//$cacheFile = 'province_country_'.$country_id.'_state_'.$state_id;
	
	//if ( ! $province_array = $ci->pyrocache->get($cacheFile)){
		if($COUNTRY->getCountryCode() == 'ES'){
			$SPAIN_STATE = $ci->states_spain_entity->init('id', $state_id);
			if(!$SPAIN_STATE){
				return array();
			}
			
			foreach($ci->db->where('region_code',$SPAIN_STATE->getRegionCode())->order_by('province_name_spanish','ASC')->get(TBL_SPAIN_PROVINCE)->result() as $item){
				$province_array[$item->id] =  ucwords( strtolower( html_entity_decode($item->province_name_spanish) ) );
			}
		}
	//	$ci->pyrocache->write($province_array, $cacheFile);
	//}
	
	$ci->db->set_dbprefix($current_dbprefix);
	return $province_array;
}

function getCityData_ioc($country_id=0, $state_id =0, $province_id =0, $city_id = 0){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$city_array = array();
	
	if(!$country_id){
		return array();
	}
	if($city_id == -2){
		return array();
	}
	$COUNTRY = $ci->countries_entity->init('id',$country_id);
	if(!$COUNTRY){
		return array();
	}
	
	if(isset($city_id) AND $city_id != 0){
		if($COUNTRY->getCountryCode() == 'ES'){
			$rs = $ci->db->where('id',$city_id)->order_by('city_name_spanish', 'ASC')->get(TBL_SPAIN_CITY)->result();
			if($rs){
				$city_array[$rs[0]->id] =  ucwords( strtolower( htmlentities($rs[0]->city_name_spanish) ) );
				return $city_array;
			}
		}else{
			$rs = $ci->db->where('id',$city_id)->order_by('city_name', 'ASC')->get(TBL_CITY)->result();
			if($rs){
				$city_array[$rs[0]->id] =  ucwords( strtolower( htmlentities($rs[0]->city_name) ) );
				return $city_array;
			}
		}
	}
	
	$cacheFile = 'city_country_'.$country_id.'_state_'.$state_id.'_province_'.$province_id;
	if ( ! $city_array = $ci->pyrocache->get($cacheFile)){
		if($COUNTRY->getCountryCode() == 'ES'){
			$SPAIN_PROVINCE = $ci->provinces_spain_entity->init('id',$province_id);
			if(!$SPAIN_PROVINCE){
				return array();
			}
			foreach($ci->db->where('province_code',$SPAIN_PROVINCE->getProvinceCode())->order_by('city_name_spanish', 'ASC')->get(TBL_SPAIN_CITY)->result() as $item){
				$city_array[$item->id] =  ucwords( strtolower( htmlentities($item->city_name_spanish) ) );
			}
		}else{
			$STATE = $ci->states_entity->init('id', $state_id);
			if(!$STATE){
				return array();
			}
			foreach($ci->db->where(array('country_code'=>$COUNTRY->getCountryCode(),'state_code'=>$STATE->getStateCode()))->order_by('city_name', 'ASC')->get(TBL_CITY)->result() as $item){
				$city_array[$item->id] =  ucwords( strtolower( htmlentities($item->city_name) ) );
			}
		}
		$ci->pyrocache->write($city_array, $cacheFile);
	}
	$ci->db->set_dbprefix($current_dbprefix);
	return $city_array;
}

function getCommercialData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$rs = $ci->db->
		query("SELECT A.* FROM default_escort_user_roles_n_benefits AS A INNER JOIN default_groups AS B 
				ON B.id=A.group WHERE B.name='commercial' AND A.status=1 ")
		->result();
	foreach($rs as $item){
		$return_array[$item->id] = $item->name ;
	}
	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;
}

function getSubcriptionData_ioc($code= 0){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$subs_array = $ci->db->where('language_id',get_language_id())->get(TBL_SUBCRIPTION_OPTION)->result();
	$ci->db->set_dbprefix($current_dbprefix);
	
	foreach($subs_array as $item){
		$return_array[$item->code] = array( $item->option, $item->price);
	}
	
	if($code){
		foreach($subs_array as $item){
			if($item->code == $code){
				$return_array = array( $item->option, $item->price);
				break;
			}
		}
	}
	
	return $return_array;
}

function getPlaceListWorkData_ioc(){	
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$place_array = $ci->db->get(TBL_PLACE_LIST)->result();
	$ci->db->set_dbprefix($current_dbprefix);
	
	foreach($place_array as $item){
		//$cityArray = getCityData_ioc($item->country_id, $item->state_id, $item->province_id ,$item->city_id	);
		//$tmpArr = array_values($cityArray); 
		$return_array[$item->id] = array( 'ITEM', $item->price);
	}
	
	return $return_array;	
}

function getPlaceListDataInfoById($place_id){
	$ci = &get_instance();
	$ci->db->set_dbprefix('default_');
	
	$res = $ci->db->where('id', $place_id)->get(TBL_PLACE_LIST)->result();
	if(!$res) return null;
	
	if($res[0]->country_id != 0){
		$country_arr = getCountryData_ioc($res[0]->country_id);
		$country = getValueOfArray($country_arr);
	}else{
		$country = '';
	}	
	
	if($res[0]->country_id != 0 AND $res[0]->state_id != 0){
		$state_arr = getStateData_ioc($res[0]->country_id, $res[0]->state_id);
		$state = getValueOfArray($state_arr);
	}else{
		$state = '';
	}
	
	if($res[0]->country_id != 0 AND $res[0]->state_id != 0 AND $res[0]->province_id != 0){
		$province_arr = getProvinceData_ioc($res[0]->country_id, $res[0]->state_id, $res[0]->province_id);
		$province =  getValueOfArray($province_arr);
	}else{
		$province = '';
	}
	
	if($res[0]->country_id != 0 AND $res[0]->state_id != 0 AND $res[0]->city_id != 0){
		$city_arr = getCityData_ioc($res[0]->country_id, $res[0]->state_id, $res[0]->province_id, $res[0]->city_id);
		$city = getValueOfArray($city_arr);
	}else{
		$city = '';
	}
	
	return array(
		'country'	=> $country,
		'state'		=> $state,
		'province'	=> $province,
		'city'		=> $city,
		'price'		=> $res[0]->price,
		'id'		=> $place_id
	);
}	

function getPackListData_ioc($code=0){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$temp = $ci->db->where('language_id',get_language_id())->get(TBL_PACKAGE_OPTION)->result();
	if($code){
		foreach($temp as $item){
			if($code == $item->code){
				$return_array = array ( $item->package, $item->price, $item->apply_period );
				break;
			}
		}
	}else{
		foreach($temp as $item){
			$return_array[$item->code]	= array ( $item->package, $item->price, $item->apply_period );
		}
	}
	/**
	$str = "SELECT A.*, B.*,A.price AS ppp,A.id AS aid FROM ".TBL_PRODUCT.
			" AS A INNER JOIN ".TBL_PACKAGE_OPTION.
			" AS B ON A.package_ids=B.id WHERE B.language_id=".get_language_id();
			
	$res = $ci->db->query($str)->result();		
	if($code){
		foreach($res as $item){
			if($code == $item->aid){
				$return_array = array ( $item->package, $item->ppp );
				break;
			}
		}
	}else{
		foreach($res as $item){
			$return_array[$item->aid] = array ( $item->package, $item->ppp );
		}
	}
	**/
	$ci->db->set_dbprefix($current_dbprefix);
	
	return $return_array;	
}

function getProfessionData_ioc($id=0){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	if($id){
		foreach($ci->db->where('language_id',get_language_id())->get(TBL_PROFESSION)->result() as $item){
			if($item->code == $id){
				$return_array[$item->code]	= $item->profession;
				break;
			}
		} 
	}else{
		foreach($ci->db->where('language_id',get_language_id())->get(TBL_PROFESSION)->result() as $item){
			$return_array[$item->code]	= $item->profession;
		}
	}
	$ci->db->set_dbprefix($current_dbprefix);
	
	return $return_array;	
}

function getPriorityData_ioc($id=0){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->get(TBL_PRIORITY_OPTION)->result() as $item){
		$return_array[$item->id]	= array ( $item->priority, $item->price, $item->priority_percentage );
	}
	
	if($id){
		foreach($ci->db->get(TBL_PRIORITY_OPTION)->result() as $item){
			if($id == $item->id){
				$return_array = array ( $item->priority, $item->price, $item->priority_percentage );
			}
		}
	}
	$ci->db->set_dbprefix($current_dbprefix);
	
	return $return_array;	
}

function getSexOptionData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_SEX_OPTION)->result() as $item){
		$return_array[$item->code]	= $item->sex ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;	
}

function getLanguagesOptionData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->get(TBL_LANGUAGE)->result() as $item){
		$return_array[$item->id]	= $item->language ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;		
}


function getLanguagesSite_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$rs = $ci->db->where('site_id',get_site_id())->get(TBL_SITE_SETTING)->result();
	$main_site_language_ids = $rs[0]->main_site_language_ids;
	
	foreach( explode(',',$main_site_language_ids) as $id ){
		if($id){
			$rc = $ci->db->where('id',$id)->get(TBL_LANGUAGE)->result();
			if($rc){
				$return_array[$rc[0]->id]	= array( $rc[0]->language, $rc[0]->code) ;
			}
		}
	}
	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;		
}

function getLanguagesSiteString_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$rs = $ci->db->where('site_id',get_site_id())->get(TBL_SITE_SETTING)->result();
	$main_site_language_ids = $rs[0]->main_site_language_ids;
	$ci->db->set_dbprefix($current_dbprefix);
	return $main_site_language_ids;	
}

function getLanguagesData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get('default_google_languages')->result() as $item){
		$return_array[$item->code_f_id]	= $item->language ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;		
}

function getHairColorOptionData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_HAIR_COLOR_OPTION)->result() as $item){
		$return_array[$item->code]	= $item->hair_color ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;			
}

function getHairLongOptionData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_HAIR_SIZE_OPTION)->result() as $item){
		$return_array[$item->code]	= $item->hair_style ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;			
}

function getHairStyleOptionData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_HAIR_STYLE_OPTION)->result() as $item){
		$return_array[$item->code]	= $item->hair_color ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;		
}

function getEyeOptionData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_EYE_OPTION)->result() as $item){
		$return_array[$item->code]	= $item->eye ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;		
}

function getHeightOptionData_ioc(){
	$min = getVariableDefineData('HEIGHT_SETTING_MIN');//155;
	$max = getVariableDefineData('HEIGHT_SETTING_MAX');//185;
	$arrayOption = array();
	for($i = $min ; $i <= $max; $i++){
		$arrayOption[$i]	= $i.' cm';
	}
	return $arrayOption;
}

function getWeightOptionData_ioc(){
	$min = getVariableDefineData('WEIGHT_SETTING_MIN');//45;
	$max = getVariableDefineData('WEIGHT_SETTING_MAX');//70;
	$arrayOption = array();
	for($i = $min ; $i <= $max; $i++){
		$arrayOption[$i]	= $i.' kg';
	}
	return $arrayOption;
}

function getMeasureOptionData_ioc(){
	$min = getVariableDefineData('MEASURE_SETTING_MIN');//60;
	$max = getVariableDefineData('MEASURE_SETTING_MAX');//150;
	$arrayOption = array();
	for($i = $min ; $i <= $max; $i++){
		$arrayOption[$i]	= $i.' cm';
	}
	return $arrayOption;
}

function getBreastsSizeOptionData_ioc(){
	$min = 1;
	$max = 40;
	$arrayOption = array();
	for($i = $min ; $i <= $max; $i++){
		$arrayOption[$i]	= $i.' cm';
	}
	return $arrayOption;
}

function getPenisSizeOptionData_ioc(){
	$min = 1;
	$max = 30;
	$arrayOption = array();
	for($i = $min ; $i <= $max; $i++){
		$arrayOption[$i]	= $i.' cm';
	}
	return $arrayOption;
}

function getScheduleInWeekData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->order_by('order','asc')->get(TBL_WEEK_DAY)->result() as $item){
		$return_array[$item->code]	= $item->week_day ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;		
}

function getHourAndMinuteOptionData_ioc(){
	$ci = &get_instance();
	if ( ! $data = $ci->pyrocache->get('hourNminuteCache'))
    {
		$data = array();
		for($i=0; $i<=23; $i++){
			//for($j=0; $j<=59; $j++){
				if($i<=9){
					$ii = '0'.$i;
				}else{
					$ii = $i;
				}
			/*	if($j<=9){
					$jj = '0'.$j;
				}else{
					$jj = $j;
				}
				*/
				$data["$ii:00"] = "$ii:00";
				$data["$ii:30"] = "$ii:30";
			//}
		}
		$ci->pyrocache->write($data, 'hourNminuteCache');
    }
    	
	return $data;
}

function getWorkingPlaceData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_WORKING_PLACE)->result() as $item){
		$return_array[$item->code]	= strip_slashes( $item->working_place );
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;		
}

function getTravelPlaceData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_TRAVEL_OPTION)->result() as $item){
		$return_array[$item->code]	= strip_slashes ($item->option) ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;	
}

function getServesToData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_SERVES_TO_OPTION)->result() as $item){
		$return_array[$item->code]	= strip_slashes( $item->option );
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;	
}

function getServicesData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_SERVICE_OPTION)->result() as $item){
		$return_array[$item->code]	= strip_slashes( $item->service );
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;	
}

function getPaymentTypesData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_PAYMENT_TYPE)->result() as $item){
		$return_array[$item->code]	= $item->type ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;		
}

function getPricingTimeData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->order_by('order','asc')->get(TBL_PRICING_TIME_OPTION)->result() as $item){
		$return_array[$item->code]	= $item->time.' '.$item->measure ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;	
}

function getTransportData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_TRANSPORT_OPTION)->result() as $item){
		$return_array[$item->code]	= $item->transport ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;		
}

function getExtrasData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach($ci->db->where('language_id',get_language_id())->get(TBL_EXTRAS_OPTION)->result() as $item){
		$return_array[$item->code]	= $item->extras ;
	}

	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;		
}

function contractDiscount_ioc($month=0){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	foreach( $ci->db->get(TBL_DISCOUNT_CONFIG)->result() as $item ){
		$return_array[$item->month_period] = $item->percent_discount;
	}
	 
	if($month != 0){
		if(in_array($month, array_keys($return_array))){
			return $return_array[$month];
		}
	}
	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;
}


function do_log($action, $userId, $username, $slug, $parameter){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$ci->action_log->do_log($action, $userId, $username, $slug, $parameter);
}

function printf_array($format, $arr)
{
    return call_user_func_array('printf', array_merge((array)$format, $arr));
}

function getEscortAgeRange(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array('max_age'=>35,'min_age'=>18);
	
	$rs = $ci->db->query("SELECT MIN(birth_date) AS max_age, MAX(birth_date) AS min_age FROM ".TBL_ESCORT."")->result();
	if($rs){
		$return_array = array('max_age'=>$rs[0]->max_age, 'min_age'=>$rs[0]->min_age);
	}
	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;
}

function getBreastSizeRange(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$rs = $ci->db->query("SELECT MIN(measure_1) AS min_size, MAX(measure_1) AS max_size FROM ".TBL_ESCORT."")->result();
	if($rs){
		$return_array = array('min_size'=>$rs[0]->min_size, 'max_size'=>$rs[0]->max_size);
	}
	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;
}

function getPriceRange(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array('min_price'=>10,'max_price'=>150);
	
	$rs = $ci->db->
			query("SELECT min_price_per_hour ,max_price_per_hour  FROM ".TBL_SITE_SETTING." WHERE site_id=".get_site_id())
			->result();
	if($rs){
		$return_array = array('min_price'=>$rs[0]->min_price_per_hour, 'max_price'=>$rs[0]->max_price_per_hour);
	}
	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;
}

function getLanguagesOfEscortsUsed(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$rs = $ci->db->query("SELECT language_ids FROM ".TBL_ESCORT."")->result();
	$idsArr = array();
	foreach($rs as $item){
		foreach(explode(',',$item->language_ids) as $id){
			$idsArr[] = $id;
		}
	}
	$idsArr = array_filter(array_unique($idsArr));
	foreach($idsArr as $id){
		$rs = $ci->db->where('id',$id)->get('default_google_languages')->result();
		if($rs){
			$return_array[$id] = $rs[0]->language;
		}
	}
	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;
}

function getCountriesOfEscortsUsed(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$countriesId = $ci->db->query("SELECT DISTINCT country_id FROM `default_escort_site_settings_on_zones` WHERE site_id=".get_site_id())->result();
	foreach( $countriesId as $item){
		$rs = $ci->db->where('id',$item->country_id)->get('default_countries')->result();
		if($rs){
			$return_array[$item->country_id] = $rs[0]->country_name;
		}
	}
	$ci->db->set_dbprefix($current_dbprefix);
	asort($return_array);
	return $return_array;
}

function getSiteCategoryBaseOnSiteSetting(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$res = $ci->db->query(
								"SELECT * FROM default_escort_categories WHERE code IN 
								(SELECT escort_category_code FROM default_escort_site_settings WHERE site_id=".get_site_id()." )
								AND language_id=".get_language_id()."	
								"
							)
			->result();
			
	$ci->db->set_dbprefix($current_dbprefix);
	if($res){
		$return_array[$res[0]->code] = $res[0]->category;
	}
	return $return_array;
}

function getAgencyListData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$return_array[0] = language_translate('agency_selectbox_select');
	$res = $ci->db->query("SELECT U.* FROM default_escort_users AS U WHERE U.permission_slug='agent' AND U.status='activated' AND U.id IN (SELECT CONCAT(user_id) FROM default_escort_escorts WHERE published=1 GROUP BY user_id) ORDER BY U.name ASC")->result();
	foreach($res as $item){
		$return_array[$item->id] = $item->name;
	}
	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;
}

function getBornCountryData_ioc(){
	$ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
	$return_array = array();
	
	$return_array[0] = language_translate('borncountry_selectbox_select');
	$res = $ci->db->query("SELECT * FROM default_escort_born_countries WHERE status='1' ")->result();
	foreach($res as $item){
		$return_array[$item->id] = $item->name;
	}
	$ci->db->set_dbprefix($current_dbprefix);
	return $return_array;
}


function getVariableDefineData($varName){
    $ci = &get_instance();
	$current_dbprefix = $ci->db->dbprefix;
	$ci->db->set_dbprefix('default_');
    
    $rs = $ci->db->where('name',$varName)->get('default_variables')->result();
    
    $ci->db->set_dbprefix($current_dbprefix);
	return ($rs)?$rs[0]->data:null;
}




